package com.easy.product.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.SeckillActivity;
import com.easy.common.service.SeckillActivityService;
import com.easy.product.mapper.SeckillActivityMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SeckillActivityServiceImpl extends ServiceImpl<SeckillActivityMapper, SeckillActivity> implements SeckillActivityService {
    @Override
    public SeckillActivity getActivityById(Integer id) {
        return super.getById(id);
    }

    @Override
    public SeckillActivity getActivityByName(String name) {
        LambdaQueryWrapper<SeckillActivity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SeckillActivity::getName, name);
        queryWrapper.eq(SeckillActivity::getIsdel, 0);
        return super.getOne(queryWrapper);
    }

    @Override
    public SeckillActivity getActivityByStatus(Integer status) {
        LambdaQueryWrapper<SeckillActivity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SeckillActivity::getStatus, status);
        queryWrapper.eq(SeckillActivity::getIsdel, 0);
        return super.getOne(queryWrapper);
    }

    @Override
    public int addActivity(SeckillActivity seckillActivity) {
        return super.save(seckillActivity)?1:0;
    }

    @Override
    public int updateActivity(SeckillActivity seckillActivity) {
        return super.updateById(seckillActivity)?1:0;
    }

    @Override
    public int deleteActivity(Integer id) {
        return super.removeById(id)?1:0;
    }

    @Override
    public int updateStatus(SeckillActivity seckillActivity) {
        return super.updateById(seckillActivity)?1:0;
    }

    @Override
    public List<SeckillActivity> getAll(SeckillActivity seckillActivity) {
        LambdaQueryWrapper<SeckillActivity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(SeckillActivity::getName, seckillActivity.getName());
        return super.list(queryWrapper);
    }

    @Override
    public IPage<SeckillActivity> getPage(SeckillActivity seckillActivity, IPage page) {
        LambdaQueryWrapper<SeckillActivity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(SeckillActivity::getName, seckillActivity.getName());
        return super.page(page);
    }
}
